﻿using System;
using System.Collections.Generic;
using System.Text;

namespace csharpcore7_ch3
{
    public interface IUndoable { void Undo(); }
    public class TextBox : IUndoable
    {
        public virtual void Undo() //虚方法实现接口
        {
            Console.WriteLine("TextBox.Undo");
        }
    }
    public class RichTextBox : TextBox
    {
        public override void Undo() => Console.WriteLine("RichTextBox.Undo");
    }
    class InterfaceExample3
    {
        static void _Main()
        {
            //不管从基类还是接口中调用接口成员，调用的都是子类的实现
            RichTextBox r = new RichTextBox();
            r.Undo();                   //RichTextBox.Undo
            ((IUndoable)r).Undo();      //RichTextBox.Undo
            ((TextBox)r).Undo();        //RichTextBox.Undo
        }        
    }

   

   
}
